﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.IO;

public partial class SpecialPlan_VerifyedSpecialPlan : System.Web.UI.Page
{
    Model.UserInfo objUserInfo = new Model.UserInfo();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            BindDrp();
            BindRpt();
        }
    }

    void BindRpt()
    {
        object[] _value = new object[2];
        _value[0] = this.drpDepartment.SelectedItem.Text;
        _value[1] = objUserInfo.UserName;
        this.rptNoVerifySpecialPlan.DataSource = new BLL.SpecialPlan().getSpecialPlanEvaluated(_value);
        this.rptNoVerifySpecialPlan.DataBind();

    }

    void BindDrp()
    {
        //部门绑定
        if (this.drpDepartment.Equals(this.drpDepartment))
        {
            this.drpDepartment.DataSource = new BLL.DepartmentInfoManager().getNoTree();
            this.drpDepartment.DataTextField = "DepartmentName";
            this.drpDepartment.DataValueField = "DepartmentId";
            this.drpDepartment.DataBind();
            ListItem _li = new ListItem("请选择部门");
            this.drpDepartment.Items.Insert(0, _li);
            //object[] _value = new object[1];
            //_value[0] = objUserInfo.UserName;
            //DataTable _userTable = new BLL.UserInfoManager().get(BLL.UserInfoManager.field.UserName.ToString(), _value);
            //if (_userTable.Rows.Count > 0)
            //{
            //    this.drpDepartment.SelectedIndex = this.drpDepartment.Items.IndexOf(this.drpDepartment.Items.FindByText(_userTable.Rows[0]["DepartmentId"].ToString()));

            //}

        }
    }

    /// <summary>
    /// 弹出小窗体事件
    /// </summary>
    /// <param name="msg"></param>
    public void ShowMessage(string msg)
    {
        EeekSoft.Web.PopupWin pop = new EeekSoft.Web.PopupWin();
        this.Controls.Add(pop);
        pop.Text = msg;
        pop.Message = msg;
        pop.Title = System.Configuration.ConfigurationManager.AppSettings["CompanyName"].ToString();
        pop.WindowScroll = true;
        pop.HideAfter = 99999999;
        pop.DockMode = EeekSoft.Web.PopupDocking.BottomLeft;
        pop.OffsetX = int.Parse(Session["_width"].ToString()) - 338;
        pop.ActionType = EeekSoft.Web.PopupAction.MessageWindow;
        pop.OffsetY = 1;
        pop.Width = 220;
        pop.Height = 170;
    }

    /// <summary>
    /// 根据逗号换行事件
    /// </summary>
    public string wrapByComma(string str)
    {
        string _content = string.Empty;
        _content = str.Replace("&lt;br&gt;", "<br>");
        //_gridView.Rows[_rowIndex].Cells[_cells].Text = _content.Replace("&gt;", ">");
        _content = str.Replace(",", "<br>");
        return _content;

    }
    protected void btnVerifyCircuit_Click(object sender, EventArgs e)
    {

    }
    protected void drpDepartment_SelectedIndexChanged(object sender, EventArgs e)
    {
        BindRpt();
    }


    ///   <summary>   
    ///   文件下载   
    ///   </summary>   
    ///   <param   name="FullFileName"></param>   
    private void FileDownload(string strFileName)
    {

        FileInfo DownloadFile = new FileInfo(strFileName);
        if (!DownloadFile.Exists)
        {
            Utility.HttpHelp.alert("无附件,请与管理员联系", Page);
            return;
        }
        Response.Clear();
        Response.ClearHeaders();
        Response.Buffer = false;
        Response.ContentType = "application/octet-stream";
        Response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(strFileName.Substring(strFileName.LastIndexOf('\\') + 1), System.Text.Encoding.UTF8));
        // Response.AppendHeader("Content-Length", DownloadFile.Length.ToString());

        Response.WriteFile(DownloadFile.FullName);
        Response.Flush();
        Response.End();

    }



    protected void rptNoVerifySpecialPlan_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
        {
            HiddenField HSpecialPlanId = e.Item.FindControl("HSpecialPlanId") as HiddenField;
            Repeater rep = e.Item.FindControl("rptNoVerifySpecialPlanDetail") as Repeater;//找到里层的repeater对象
            Label lblAlert = e.Item.FindControl("lblAlert") as Label;
            Button btnDownLoad = e.Item.FindControl("btnDownLoad") as Button;
            HiddenField HAttachmengPath = e.Item.FindControl("HAttachmengPath") as HiddenField;
            HiddenField HState = e.Item.FindControl("HState") as HiddenField;
            HiddenField HEvaluatePeopleVerifyOpinion = e.Item.FindControl("HEvaluatePeopleVerifyOpinion") as HiddenField;

            
            if (HAttachmengPath.Value.Length > 0)
            {
                lblAlert.Visible = false;
                btnDownLoad.Visible = true;
            }
            else
            {
                lblAlert.Visible = true;
                btnDownLoad.Visible = false;
            }
             



            object[] _value = new object[1];
            _value[0] = Convert.ToInt32(HSpecialPlanId.Value);
            rep.DataSource = new BLL.SpecialPlan().GetSpecialPlanDetailBySpecialId(_value);
            rep.DataBind();


        }
    }

    protected void rptNoVerifySpecialPlan_ItemCommand(object source, RepeaterCommandEventArgs e)
    {
        if (e.CommandName == "DownLoad")
        {
            string path = e.CommandArgument.ToString();
            Response.Write(path);
            FileDownload(path);
        }
    }


    /// <summary>
    /// 待审核Reapeater绑定
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void rptNoVerifySpecialPlanDetail_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
        {
            HiddenField HSpecialPlanDetailId = e.Item.FindControl("HSpecialPlanDetailId") as HiddenField;
            HiddenField HState = e.Item.FindControl("HState") as HiddenField;
            HiddenField HEvaluatePeopleVerifyOpinion = e.Item.FindControl("HEvaluatePeopleVerifyOpinion") as HiddenField;
            HiddenField HVerifyPeople = e.Item.FindControl("HVerifyPeople") as HiddenField;
            HiddenField HEvaluatePeople = e.Item.FindControl("HEvaluatePeople") as HiddenField; 
           
        }
    }

}